package com.feinno.urcs.group.log;

import com.feinno.superpojo.type.EnumInteger;
import com.feinno.urcs.group.entity.GroupFileInfo;
import com.feinno.urcs.group.entity.GroupMessageType;

import static com.feinno.urcs.group.entity.GroupMessageType.*;

/**
 * Created by wuhao on 15-10-14.
 */
public enum MessageContentType implements EnumInteger {

	UNKNOWN(0), TXT(1), IMAGE(2), AUDIO(3), VIDEO(4), LOCATION(5), VCARD(6), VEMOTICON(7), CLOUD(8), PUBACC(9);

	int value;

	private MessageContentType(int value) {
		this.value = value;
	}

	public int intValue() {
		return value;
	}

	public static MessageContentType parse(int value) {
		switch (value) {
			case 0:
				return UNKNOWN;
			case 1:
				return TXT;
			case 2:
				return IMAGE;
			case 3:
				return AUDIO;
			case 4:
				return VIDEO;
			case 5:
				return LOCATION;
			case 6:
				return VCARD;
			case 7:
				return VEMOTICON;
			case 8:
				return CLOUD;
			case 9:
				return PUBACC;
			default:
				return null;
		}
	}

	public static MessageContentType parse(GroupFileInfo groupFileInfo) {
		if (groupFileInfo == null) return UNKNOWN;
		String fileName = groupFileInfo.getFileName().toLowerCase();
		if (fileName.endsWith("mp4") || fileName.endsWith("avi") || fileName.endsWith("mpeg")) {
			return VIDEO;
		} else if (fileName.endsWith("amr") || fileName.endsWith("mp3") || fileName.endsWith("wav")) {
			return AUDIO;

		} else if (fileName.endsWith("jpeg") || fileName.endsWith("gif") || fileName.endsWith("bmp") || fileName.endsWith("png") || fileName.endsWith("jpg")) {
			return IMAGE;
		} else if (fileName.endsWith("vcf")) {
			return VCARD;
		} else if (fileName.endsWith("location.xml") || groupFileInfo.getMessageType() == GroupMessageType.LOCATION) {
			return LOCATION;
		} else {
			return UNKNOWN;
		}
	}

	public static MessageContentType parse(String contentType) {

		switch (contentType) {
			case "text/plain":
				return TXT;
			case "text/pic":
				return IMAGE;
			case "text/audio":
				return AUDIO;
			case "text/video":
				return VIDEO;
			case "text/location":
				return LOCATION;
			case "text/card":
				return VCARD;
			case "text/outce":
				return VEMOTICON;

			default:
				return UNKNOWN;
		}


	}

	public static MessageContentType parse(GroupMessageType contentType) {
		switch (contentType.intValue()) {
			case 1:
				return TXT;
			case 2:
				return IMAGE;
			case 3:
				return AUDIO;
			case 4:
				return VIDEO;
			case 5:
				return TXT;
			case 6:
				return LOCATION;
			case 7:
				return VCARD;
			case 8:
				return UNKNOWN;
			case 9:
				return CLOUD;
			default:
				return UNKNOWN;
		}
	}
}